# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>
#This value is here because some python package names have capital letters
#while there is a strong preference for lowercase letters in ArchLinux and
#MSYS packages.

_pyname=PyYAML
_realname=yaml
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=6.0.2
pkgrel=3
pkgdesc="Python bindings for YAML, using fast libYAML library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://pyyaml.org/'
msys2_repository_url="https://github.com/yaml/pyyaml/"
msys2_references=(
  'purl: pkg:pypi/pyyaml'
  "cpe: cpe:/a:pyyaml:pyyaml"
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-libyaml")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname,,}-${pkgver}.tar.gz"
        0001-setup-disable-distutils.patch)
sha256sums=('d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e'
            '243f6df169452f8c452f94c8282c00ba3822db0b4dea137532eaa7e4b6b36688')

prepare() {
  cd "${srcdir}"/${_pyname}-${pkgver}
  patch -p1 -i "${srcdir}/0001-setup-disable-distutils.patch"
}

build() {  
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}"
  cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation -C--with-libyaml
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 CHANGES README.md -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}"
}
